<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">

	<head>
	
		<c:set value="${pageContext.request.contextPath}" var="basePath"></c:set>
		<jsp:include page="include/head.jsp"></jsp:include>
		<jsp:include page="include/js.jsp"></jsp:include>
	
		<!-- Styles -->
		<link href="${basePath}/resources/css/sketchpadNew.css" rel="stylesheet">
	
		<!-- Sketchpad Libs -->
		<jsp:include page="include/libs.jsp"></jsp:include>
		
		<!-- CoupledObjectServer -->
		<script src="${cosServer}/resources/js/sync_blocking.js"></script>
		
		<!-- Sketchpad -->
		<jsp:include page="include/sketchpadLib.jsp"></jsp:include>
		
	</head>
	
	<body>
	
		<jsp:include page="include/sketchpadView.jsp"></jsp:include>
		
		<script type="text/javascript">
			$(function(){
				
				var user = {
					id : "${user.id}",
					name : "${user.name}",
					lastname : "${user.lastname}",
					username : "${user.username}",
					type : "${user.type}"
				};
				
				var subjectVersion = {
					id: "${subjectVersion.id}",
					name: "${subjectVersion.name}"
				};
				
				var activity = {
					id: "${activity.id}",
					name: "${activity.name}"
				};
				
				var options = {
					useUI: true,
					coupling: {
						enabled: true,
						cosServer: '${cosServer}/',
						activityAdapter: null,
						personalAdapter: null
					}
				};
				
				if ( options.coupling.enabled ) {
					options.coupling.activityAdapter = new ClientAdapter(options.coupling.cosServer);
					options.coupling.activityAdapter.joinSession("activity" + activity.id);
					
					options.coupling.personalAdapter = new ClientAdapter(options.coupling.cosServer);
					options.coupling.personalAdapter.joinSession("user" + user.id + "-activity" + activity.id);
				}
				
				Skt.sketchpad = new Skt.SketchpadController(
					"${basePath}",
					subjectVersion,
					activity,
					user,
					options
				);
				
				Skt.Init.init(Skt.sketchpad);
				
				if ( options.coupling.enabled ) {
					options.coupling.activityAdapter.start(0);
					options.coupling.personalAdapter.start(0);
				}
				
			});
		</script>	
		
	</body>
	
</html>
